function [f] = fobj(Z, W, eta, X, y, alphav, invsigmawsqr, invsigmaetasqr, invsigmaxsqr, C, ell)
% -log(prior)
f = (0.5*invsigmawsqr)*norm(W, 'fro')^2 + numel(W)*log(sqrt(2*pi/invsigmawsqr)) + ...
    (0.5*invsigmaetasqr)*norm(eta, 'fro')^2 + numel(eta)*log(sqrt(2*pi/invsigmaetasqr)) - ...
    logpibp(Z, alphav);

% -log(likelihood)
f = f + 0.5*(sum((X-W*Z').^2)*invsigmaxsqr);

% +emperical loss
f = f + C*sum(max(ell - y.*(Z(1:numel(y),:)*eta), 0));

end
